<template>
    <!-- <van-tabs v-model:active="active">
        <van-tab title="组件A">
            <van-divider>setup组件A</van-divider>
            <p>Data: [{{a}}]</p>
            <p>
                方法:
                <van-button type="success" size="small" @click="logA">logA</van-button>
            </p>
        </van-tab>
        <van-tab title="组件B">
            <van-divider>setup组件B</van-divider>
            <p>data: [{{b}}]</p>
            <p>
                方法:
                <van-button type="danger" size="small" @click="logB">logB</van-button>
            </p>
        </van-tab>
        <van-tab title="组件C">
            <van-divider>setup组件C</van-divider>
            <p>data: [{{c}}]</p>
            <p>
                方法:
                <van-button type="warning" size="small" @click="logC">logC</van-button>
            </p>
        </van-tab>
    </van-tabs> -->
    <div class="chooseWrap">
        <img class="logo" alt="Vue logo" src="../assets/logo2.png" />
        <HelloWorld  msg="江门广电网络" />
        <!-- <van-button type="primary" size="large" @click="road2Book">广告位预约</van-button> <br><br> -->
        <!-- <van-button type="warning" size="large" @click="road2Book">广告位录入</van-button> <br> <br> -->
        <!-- <van-button type="warning" size="large" @click="road2Book">广告位查询</van-button> <br> <br> -->
        <van-button type="info" size="large" @click="loginRegister" > 登录鉴权 </van-button> <br> <br>
        <!-- <van-button type="warning" size="large" @click="road2RenSurveySale">销售端入口</van-button> <br> <br> -->
        <!-- <van-button type="warning" size="large" @click="road2RenSurveyVerty">核销端入口</van-button> <br> <br> -->
        <van-button type="warning" size="large" @click="toBuilding">新建户型图</van-button> <br> <br>
        <van-button type="warning" size="large" @click="road2Apartment">小区户型图鉴</van-button> <br> <br>
        <van-button type="warning" size="large" @click="toSong">K 歌 排 行</van-button> <br> <br>
        <!-- <van-button type="info" @click="toInstall" size="large"> 上门服务登记 </van-button> -->

        <!-- <van-button type="warning" size="large" @click="road2Survey">一线评分表单</van-button> <br> <br> -->
        
    </div>
</template>

<script >
    import { ref, onMounted, getCurrentInstance } from 'vue'
    import {useRouter} from 'vue-router'
    import { useStore } from 'vuex'
    import useA from './../components/comA.js'
    import useB from './../components/comB.js'
    import useC from './../components/comC.js'
    import HelloWorld from '../components/HelloWorld.vue'
    import utils from "../router/util";
    import { faker } from '@faker-js/faker';

export default {
  setup() {
    let router = useRouter();
    const { getters, dispatch } = useStore()
    let active = ref(0)
    // let { a, logA } = useA()
    // let { b, logB } = useB()
    // let { c, logC } = useC()
    const username = ref('');
    const password = ref('');
    const onSubmit = (values) => {
      console.log('Submit', values);
    }
    const road2Book = ()=>{
        router.push({
            name:'booking'
        })    }
    const road2RenSurveySale = ()=>{
        let haveUser = utils.getCookie('user')
        let userType = utils.getCookie('user_type')
        if(haveUser && haveUser.length>0 && userType=='sale'){
            router.push({
                name: 'saleRecord',
                query:{
                    name: 'sale',
                    road: 'test'
                    }
                })
        }else{
            router.push({
                name: 'loginSale',
                query: { entryRoom: 'sale'  }
            })
        }
    }
    const road2RenSurveyVerty = ()=>{
        let haveUser = utils.getCookie('user')
        let userType = utils.getCookie('user_type')
        if(haveUser && haveUser.length>0 && userType=='verty'){
            router.push({
                name: 'vertyCust',
                query:{
                    name: 'vertyCust',
                    road: 'test'
                    }
                })
        }else{
            router.push({
                name: 'loginSale',
                query: { entryRoom: 'verty'  }
            })
        }
    }
    const road2Survey = ()=>{
         router.push({
            name: 'indexSurvey'
        })
    }
    const road2Apartment = ()=>{
        router.push({
            name: 'apartmentPic'
        })
    }
    const toSong = ()=> {
        router.push({
            name: 'peopleSing'
        })
    }
    const toBuilding = ()=>{
        router.push({
            name: 'makeComplex'
        })
    }
    const loginRegister = ()=> {
        router.push({
            name: 'loginMail'
        })
    }
    const toInstall = ()=> {
        let rand1 = Math.floor(Math.random() * 10 + 1);
        let rand2 = Math.floor(Math.random() * 10 + 1);
        let name = faker.name.firstName()+ rand1 + rand2
        router.push({
            name: 'installPage',
            query: { name: name   }
        })
    }
    onMounted(async()=>{
        console.log('index vuex test')
        let res = await dispatch('User/setMainRoute', '/')
        // const auth = $mapp.auth({ persistence: "local" });
        // await auth
        // .anonymousAuthProvider()
        // .signIn()
        // .then(() => {
        //     // const user = $mapp.auth().hasLoginState();
        //     // console.log("匿名登录", user.isAnonymousAuth);
        //     //在登录成功的回调中连接数据库
        //     const db = $mapp.database();  
        //     let dbdata =  db.collection("adroom").add({'test_font':'aaaaaaaa', 'other':'llllllllllll'}).then(
        //         (res)=>{  console.log("数据库成功", res); }
        //     )  
        // })
        // .catch(err => {
        //     console.log('云开发',err);
        // });
        
        const db = $mapp.database();  
        // let dbdata =  db.collection("adroom").add({'test_font':'111', 'other':'llllllllllll'}).then(
        //     (res)=>{  console.log("数据库成功", res); }
        //     )  

        })
    console.log('index.vue test')
    // const { proxy } = getCurrentInstance()
    const currentInstance = getCurrentInstance()
    const { $mapp } = currentInstance.appContext.config.globalProperties
    return {
      username,
      password,
      onSubmit,
      road2Book,
      road2RenSurveySale,
      road2RenSurveyVerty,
      road2Survey,
      road2Apartment,
      toSong,
      loginRegister,
      toBuilding,
      toInstall
    };  
  },
    components:{
        HelloWorld
    }
};

</script>

<style scoped>
    p {
        line-height: 1.8;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .chooseWrap{
        margin-top: 190px;
        width: 80%;
        margin: 21px auto 10px auto;
    }
    .logo {
        width: 100px;
        border-radius: 40rpx;
        margin-top: 2.67rem;
        margin-bottom: 0.026667rem;
    }
    .hello {
        margin-top: 100px;
    }
</style>


<!-- select concat('',fdate) fdate,curday,fmonth from 
`bd_tj_fmonth` -->